package servlet;

import bean.User;
import service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author : liuchangling
 * @Descrition :
 * @Date： Created in 5:37 下午 2021/5/30
 */
@WebServlet(name = "UpdateUserServlet", urlPatterns = "/update")
public class UpdateUserServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        User user = new User();
        String s = request.getParameter("sno");
        System.out.println("sno" + s);
        int sno = Integer.parseInt(s);
        user.setSno(sno);
        String name = new String(request.getParameter("name").getBytes("ISO-8859-1"), "UTF-8");
        user.setName(name);
        String sex = new String(request.getParameter("sex").getBytes("ISO-8859-1"), "UTF-8");
        user.setSex(sex);
        String date = request.getParameter("birthday");
        user.setBirthday(date);
        String mail = request.getParameter("mail");
        user.setMail(mail);
        String remark = new String(request.getParameter("remark").getBytes("ISO-8859-1"), "UTF-8");
        user.setRemark(remark);
        System.out.println(user.toString());
        UserService userService = new UserService();
        boolean isSuccess = userService.updateUserService(user);
        if (isSuccess == true) {
            response.sendRedirect("updateAlert.jsp");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
